package com.drools.drools.chapter4;

import com.drools.drools.BaseTest;
import com.drools.drools.model.Person;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;

/**
 * Created with IntelliJ IDEA.
 * User: mishuai
 * Date: 2019-04-25
 * Time: 21:52
 * Des:
 */
public class FactHandlerTest extends BaseTest {

    KieSession kieSession=this.getKieSession("fact-handler-group");

    @Test
    public void testHadler(){
        Person p=new Person();
        p.setAge(81);

        FactHandle handle=kieSession.insert(p);
        System.out.println(handle.toExternalForm());

        int count=kieSession.fireAllRules();
        System.out.println("Fire " + count + " rule(s)!");
        //System.out.println("The new discount is " + c1.getDiscount() + "%");
       // System.out.println("The new discount is " + c2.getDiscount() + "%");

      /*  kieSession.delete();
        kieSession.update();
        kieSession.getAgenda();
        kieSession.fireAllRules();
        kieSession.dispose();
        kieSession.getIdentifier();*/
        Person pp=kieSession.getKieRuntime(Person.class);
        System.out.println("++++"+pp);
        p.setAge(90);
        kieSession.getAgenda().getAgendaGroup("fact-handler-group").setFocus();
        kieSession.update(handle,p);
        System.out.println("++++==="+pp);
        int cou=kieSession.fireAllRules();
        System.out.println("++++----"+pp);
        System.out.println("Fire " + count + " rule(s)!");
        kieSession.dispose();
    }




}
